package com.api.shopapi.mapper;

import com.api.shopapi.entity.NursingRecord;
import com.api.shopapi.entity.NursingRecord;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
@Mapper
public interface NursingRecordMapper {

    @Insert("insert into nursing_record " +
            "(NursingRecordCode," +
            "ElderlyCode," +
            "ElderlyName," +
            "NurseCode," +
            "NurseName," +
            "NursingItemCode," +
            "NursingItemName," +
            "CreateTime," +
            "Remarks," +
            "StaffCode," +
            "InstitutionCode," +
            "NurseAideCode," +
            "NurseAideName," +
            "MedicinerCode," +
            "MedicinerName," +
            "RecordType) " +
            "values (" +
            "#{nursingRecord.NursingRecordCode} ," +
            "#{nursingRecord.ElderlyCode} ," +
            "#{nursingRecord.ElderlyName}," +
            "#{nursingRecord.NurseCode}," +
            "#{nursingRecord.NurseName}," +
            "#{nursingRecord.NursingItemCode} ," +
            "#{nursingRecord.NursingItemName} ," +
            "#{nursingRecord.CreateTime} ," +
            "#{nursingRecord.Remarks} ," +
            "#{nursingRecord.StaffCode} ," +
            "#{nursingRecord.InstitutionCode}," +
            "#{nursingRecord.NurseAideCode} ," +
            "#{nursingRecord.NurseAideName} ," +
            "#{nursingRecord.MedicinerCode} ," +
            "#{nursingRecord.MedicinerName} ," +
            "#{nursingRecord.RecordType} )")
    int insert(@Param("nursingRecord") NursingRecord nursingRecord);

    @Update("update nursing_record" +
            " set" +
            " Status=#{nursingRecord.Status}, " +
            " Lon=#{nursingRecord.Lon}, " +
            " Lat=#{nursingRecord.Lat}, " +
            " Address=#{nursingRecord.Address}, " +
            " StartTime=#{nursingRecord.StartTime}, " +
            " EndTime=#{nursingRecord.EndTime} " +
            " where NursingRecordCode=#{nursingRecord.NursingRecordCode} ")
    int update(@Param("nursingRecord") NursingRecord nursingRecord);

    @Delete("delete from nursing_record where NursingRecordCode=#{nursingRecordCode} ")
    int delete(@Param("nursingRecordCode") String nursingRecordCode);

    @Select("select  * from nursing_record where NursingRecordCode=#{nursingRecordCode} limit 1")
    NursingRecord getByNursingRecordCode(@Param("nursingRecordCode") String nursingRecordCode);

    @Select("select  * from nursing_record where InstitutionCode=#{institutionCode} order by CreateTime desc")
    List<NursingRecord> getListByInstitutionCode(@Param("institutionCode") String institutionCode);

    @Select("select * from nursing_record where ElderlyCode=#{elderlyCode} order by CreateTime desc")
    List<NursingRecord> getPageListByElderlyCode(@Param("elderlyCode") String elderlyCode);


    @Select("select NursingRecordCode from nursing_record" +
            " where ElderlyCode=#{elderlyCode}" +
            " and (CreateTime between #{beginTime} and #{endTime})" +
            " and Status in(2,3)")
    List<NursingRecord> listByElderlyCodeTime(@Param("elderlyCode") String elderlyCode,
                                              @Param("beginTime") Date beginTime,
                                              @Param("endTime") Date endTime);


    @Select("select  * from nursing_record where" +
            " InstitutionCode in (select institutionCode from institution where governmentCode=#{governmentCode}) " +
            " order by CreateTime desc")
    List<NursingRecord> listByGovCode(@Param("governmentCode") String governmentCode);

    @Select("<script>" +
            "select * from nursing_record" +
            " where InstitutionCode in (select institutionCode from institution where governmentCode=#{governmentCode})" +
            "<if test =' status !=-1 '>" +
            " and Status=#{status} " +
            "</if>" +
            " order by CreateTime desc"+
            "</script>")
    List<NursingRecord> listByGovCodeStatus(@Param("governmentCode") String governmentCode,
                                            @Param("status")int status);





    @Select("<script>" +
            "select * from nursing_record" +
            " where institutionCode=#{institutionCode}" +
            "<if test =' status !=-1 '>" +
            " and Status=#{status} " +
            "</if>" +
            " order by CreateTime desc"+
            "</script>")
    List<NursingRecord> listByInsCode(@Param("institutionCode") String institutionCode,@Param("status")int status);

    @Select("<script>" +
            "select * from nursing_record" +
            " where medicinerCode=#{medicinerCode}" +
            "<if test =' status !=-1 '>" +
            " and Status=#{status} " +
            "</if>" +
            " order by CreateTime desc"+
            "</script>")
    List<NursingRecord> listByMedicinerCode(@Param("medicinerCode") String medicinerCode,@Param("status")int status);

    @Select("<script>" +
            "select  * from nursing_record" +
            " where NurseCode=#{nurseCode}" +
            "<if test =' status !=-1 '>" +
            " and Status=#{status} " +
            "</if>" +
            " order by CreateTime desc"+
            "</script>")
    List<NursingRecord> listByNurseCode(@Param("nurseCode") String nurseCode,@Param("status")int status);

    @Select("<script>" +
            "select  * from nursing_record" +
            " where NurseAideCode=#{nurseAideCode}" +
            "<if test =' status !=-1 '>" +
            " and Status=#{status} " +
            "</if>" +
            " order by CreateTime desc"+
            "</script>")
    List<NursingRecord> listByNurseAideCode(@Param("nurseAideCode") String nurseAideCode,@Param("status")int status);




}
